package hutoolandguava;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author ZH
 */
public class ListRemoveTest {
    public static void main(String[] args) {
        List<String> list1 = Lists.newArrayList("a","b","c");
        // 第一种方式 迭代器remove(collection类已经封装好removeIf方法,内部使用迭代器)
        list1.removeIf(s -> s.equals("a"));
        System.out.println("list1"+list1);


        // 第二种方式 fori 循环
        List<String> list2 = Lists.newArrayList("a","b","c");
        for (int i = 0; i < list2.size(); i++) {
            if (list2.get(i).equals("a")){
                list2.remove(i);
                i--;
            }
        }
        System.out.println("list2"+list2);
    }
}
